|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.NeuroSky.Util.MathHelper
public class MathHelper
This class implements a bunch of utility functions to perform various
transformation and computational operations. Some of the functions are
simply to fill holes in J2ME's implementation of the Math class.
| Constructor Summary | |
|---|---|
MathHelper()
|
|
| Method Summary | |
|---|---|
static float |
clamp(float t,
float floor,
float ceiling)
Limit a value to between floor and ceiling. |
static Vector2 |
cubicBezier(Vector2 p0,
Vector2 p1,
Vector2 p2,
Vector2 p3,
float t)
Generate a point in a cubic Bezier curve defined by two anchor and two control points, and a parameter. |
static int |
dampColor(int startColor,
float dampFactor)
Apply a multiplicative factor to each component in a color represented by an integer (0x00RRGGBB). |
static float |
exp(float x)
Calculate the value of e^x given an input x. |
static float |
lerp(float start,
float end,
float t)
Linearly interpolate a value between the current value and target value. |
static int |
lerpColor(int startColor,
int endColor,
float t)
Linearly interpolate between two colors. |
static float |
log(float x)
Calculate the natural log of an input x, i.e. |
static float |
normalizeValue(float value)
Perform a custom normalization procedure on a value, involving applying a natural logarithm, then scaling the number to a range between 0 and 1. |
static Vector2 |
rotate(float angle,
Vector2 point)
Rotate a point about the origin (0,0) over an angle. |
static float |
smoothDamp(float current,
float target,
float[] currentVelocity,
int index,
float smoothTime,
float deltaTime)
Critically damp a value towards a target value. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public MathHelper()
| Method Detail |
|---|
public static float lerp(float start,
float end,
float t)
start - the starting valueend - the ending valuet - the parameter
public static int lerpColor(int startColor,
int endColor,
float t)
startColor - the starting color, defined by 0x00RRGGBBendColor - the finishing color, defined by 0x00RRGGBBt - the parameter
public static float clamp(float t,
float floor,
float ceiling)
floor and ceiling. This may be useful
for making sure that a number never exceeds a certain range.
t - the value to be clampedfloor - the minimum value the returned value should takeceiling - the maximum value the returned value should take
public static int dampColor(int startColor,
float dampFactor)
startColor - the initial color, in the form 0x00RRGGBBdampFactor - the multiplicative factor applied to the color
public static float exp(float x)
e^x given an input x. This only
gives us good precision to about x = +/- 2, since it's calculated using a fairly
coarse Power Series approximation.
x - the value that e is raised to
public static float log(float x)
x, i.e. ln(x). This function gives
us reasonably good precision, and is accurate to around 3 significant figures. The precision
of this function is limited by the accuracy of a T(4) Taylor Series approximation of the
natural logarithm function between 1 and 2.
x - the value from which the natural log should be calculated
x
public static float smoothDamp(float current,
float target,
float[] currentVelocity,
int index,
float smoothTime,
float deltaTime)
current - the current valuetarget - the target valuecurrentVelocity - an array of floats storing the current velocity x'(0)index - the index into the currentVelocity array referencing the desired float elementsmoothTime - - the time taken to reach the target valuedeltaTime - - the elapsed time since the last call to this method
public static Vector2 rotate(float angle,
Vector2 point)
angle - the angle (in radians) over which to rotate the pointpoint - the point to be rotated
public static Vector2 cubicBezier(Vector2 p0,
Vector2 p1,
Vector2 p2,
Vector2 p3,
float t)
p0 - the starting anchor pointp1 - the first control pointp2 - the second control pointp3 - the ending anchor pointt - the parameter for the Bezier curve
public static float normalizeValue(float value)
value - the value to be normalized
0 and 1.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||